package com.speedtickets.rest.utils;

import com.speedtickets.rest.exceptions.ForbiddenKeyException;
import com.speedtickets.rest.exceptions.InvalidKeyException;

public class AuthorizationUtils {
	
	private static final String ADMIN_KEY = "4dm1nk3y4uth0r1t3";
	
	private static final String GUEST_KEY = "gu3stk3y4uth0r1t3";
	
	public void retrictKeys( String apiKey ) throws InvalidKeyException, ForbiddenKeyException{
		if(apiKey == null){
			throw new InvalidKeyException();
		} else if(!apiKey.equals(ADMIN_KEY) && !apiKey.equals(GUEST_KEY)){
			throw new InvalidKeyException();
		} else if(!apiKey.equals(ADMIN_KEY) && apiKey.equals(GUEST_KEY)) {
			throw new ForbiddenKeyException();
		}
	}
	
	public void noRestriction(String apiKey) throws InvalidKeyException{
		if(apiKey == null){
			throw new InvalidKeyException();
		} else if(!apiKey.equals(ADMIN_KEY) && !apiKey.equals(GUEST_KEY)){
			throw new InvalidKeyException();
		}
	}
}
